from django.db import models

# Create your models here.


class Duty(models.Model):
    """
        职务
    """
    duty_text = models.CharField(max_length=20)
    duty_status = models.BooleanField(default=True)


class Subject(models.Model):
    """
        学科
        增加学科状态，历史学科，可以调整为False
    """
    subject_text = models.CharField(max_length=50, unique=True)
    subject_status = models.BooleanField(default=True)


class Course(models.Model):
    """
        科目
        设置科目状态，过时的科目可以调整为False
    """
    subject_code = models.ForeignKey(Subject, on_delete=models.CASCADE)
    course_text = models.CharField(max_length=30, null=True, blank=True, unique=True)
    course_status = models.BooleanField(default=True)


class Grade(models.Model):
    """
        班级
        设置班级状态，毕业的班级，可以调整为False
    """
    course_code = models.ForeignKey(Course, on_delete=models.CASCADE)
    grade_text = models.CharField(max_length=30, null=True, blank=True, unique=True)
    grade_status = models.BooleanField(default=True)    


class User(models.Model):
    """
        用户数据库
    """
    duty_code = models.ForeignKey(Duty, on_delete=models.CASCADE)
    grade_code = models.ForeignKey(Grade, on_delete=models.CASCADE)
    user_code = models.CharField(max_length=10, unique=True)
    user_name = models.CharField(max_length=30)
    user_sex = models.CharField(max_length=6)
    user_identity = models.CharField(max_length=18, unique=True)       # 身份证
    user_phone = models.CharField(max_length=11, unique=True)
    user_pwd = models.CharField(max_length=18)
    account_status = models.BooleanField(default=True)
    update_date = models.DateTimeField(auto_now=True)


class Score(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    score_text = models.FloatField(default=0, null=True, blank=True)
    credit_text = models.IntegerField(default=100, null=True, blank=True)  # 学分




